package cn.jason.ymcc.controller;

import cn.jason.ymcc.doc.CourseDoc;
import cn.jason.ymcc.dto.CourserSearchDto;
import cn.jason.ymcc.result.JSONResult;
import cn.jason.ymcc.result.PageList;
import cn.jason.ymcc.service.ICourseEsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 课程Es相关控制层
 */
@RestController
public class CourseEsController {
    @Autowired
    private ICourseEsService courseEsService;

    /**
     * 新增上架
     * 保存课程到Es
     * @param doc
     * @return
     */
    @PostMapping("/saveCourse")
    public JSONResult saveCourse(@RequestBody CourseDoc doc){
        courseEsService.saveCourse(doc);
        return JSONResult.success();
    }
    /**
     * 删除下架
     * 保存课程到Es
     * @param doc
     * @return
     */
    @PostMapping("/deleteCourse")
    public JSONResult deleteCourse(@RequestBody CourseDoc doc){
        courseEsService.deleteCourse(doc);
        return JSONResult.success();
    }

    /**
     * 搜索课程
     * @param dto
     * @return
     */
    @PostMapping("/course/search")
    public PageList<CourseDoc> search(@RequestBody CourserSearchDto dto){
        return courseEsService.search(dto);
    }
}
